home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / UPC12BS1.ZIP / MAIL / MAILSEND.C < prev    next >
C/C++ Source or Header  |  1993-10-03  |  36KB  |  1,020 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    m a i l s e n d . c                                             */
  3. /*                                                                    */
  4. /*    Subroutines for sending mail for UUPC/extended                  */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*       Changes Copyright (c) 1989-1993 by Kendra Electronic         */
  9. /*       Wonderworks.                                                 */
  10. /*                                                                    */
  11. /*       All rights reserved except those explicitly granted by       */
  12. /*       the UUPC/extended license agreement.                         */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*                          RCS Information                           */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*
  20.  *    $Id: mailsend.c 1.6 1993/10/04 03:57:20 ahd Exp $
  21.  *
  22.  *    Revision history:
  23.  *    $Log: mailsend.c $
  24.  * Revision 1.6  1993/10/04  03:57:20  ahd
  25.  * Clarify error message
  26.  *
  27.  * Revision 1.5  1993/08/02  03:24:59  ahd
  28.  * Further changes in support of Robert Denny's Windows 3.x support
  29.  *
  30.  * Revision 1.4  1993/07/31  16:26:01  ahd
  31.  * Changes in support of Robert Denny's Windows support
  32.  *
  33.  */
  34.  
  35. /*--------------------------------------------------------------------*/
  36. /*                        System include files                        */
  37. /*--------------------------------------------------------------------*/
  38.  
  39. #include <ctype.h>
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43. #include <sys/types.h>
  44. #include <sys/stat.h>
  45.  
  46. /*--------------------------------------------------------------------*/
  47. /*                    UUPC/extended include files                     */
  48. /*--------------------------------------------------------------------*/
  49.  
  50. #include "lib.h"
  51.  
  52. #include "arpadate.h"
  53. #include "expath.h"
  54. #include "execute.h"
  55. #include "hlib.h"
  56. #include "mlib.h"
  57. #include "alias.h"
  58. #include "mail.h"
  59. #include "maillib.h"
  60. #include "mailblib.h"
  61. #include "mailsend.h"
  62. #include "safeio.h"
  63. #include "address.h"
  64.  
  65. /*--------------------------------------------------------------------*/
  66. /*                     Local function prototypes                      */
  67. /*--------------------------------------------------------------------*/
  68.  
  69.  static char *ExplodeAlias(char *header ,
  70.                       const char *alias,
  71.                       FILE *stream,
  72.                       const boolean resent);
  73.  
  74.  
  75.  static void PutHead( const char *label,
  76.                       const char *operand,
  77.                       FILE *stream,
  78.                       const boolean resent);
  79.  
  80.  static boolean Append_Signature(FILE *mailbag,
  81.                      const boolean alternate);
  82.  
  83.  static void Prompt_Input( char *tmailbag,
  84.                           FILE *fmailbag,
  85.                            char *subject,
  86.                           const int current);
  87.  
  88.  static boolean Subcommand( char *buf,
  89.                            FILE *fmailbag,
  90.                            char *tmailbag,
  91.                            char *subject,
  92.                            const int current_msg);
  93.  
  94.  static void CopyOut( const char* input);
  95.  
  96.  static void filter( char *tmailbag, char *command);
  97.  
  98.  static char *GetString( char *input);
  99.  
  100. currentfile();                /* Define current file for panic()     */
  101.  
  102. /*--------------------------------------------------------------------*/
  103. /*    E x p l o d e A l i a s                                         */
  104. /*                                                                    */
  105. /*    Resolves an alias, exploding it into a list if needed.          */
  106. /*--------------------------------------------------------------------*/
  107.  
  108.  static char *ExplodeAlias(char *header ,
  109.                       const char *alias,
  110.                       FILE *stream,
  111.                       const boolean resent)
  112. {
  113.    char *fullname;
  114.    char buffer[LSIZE];
  115.  
  116.    if ((alias == NULL) || (strlen(alias) == 0))
  117.    {
  118.       printmsg(0,"ExplodeAlias: NULL or empty string for argument");
  119.       panic();
  120.    }
  121.  
  122.    fullname = AliasByNick(alias);
  123.  
  124.    printmsg(4,"Processing alias '%s', result '%s'", alias,
  125.       (fullname == NULL) ? alias : fullname);
  126.  
  127.    if (fullname == NULL)            /* No alias found for user?     */
  128.    {                                /* No --> Try node lookup       */
  129.       char user[MAXADDR];
  130.       char node[MAXADDR];
  131.       char path[MAXADDR];
  132.       char bucket[MAXADDR];
  133.  
  134.       ExtractAddress(bucket, (char *) alias, FALSE);
  135.       user_at_node(bucket, path, node, user);
  136.       fullname = AliasByAddr( node, user);
  137.  
  138.       if (fullname == NULL)         /* Did we come up empty?         */
  139.       {
  140.          char *hisuser, *hisnode;
  141.  
  142.          hisuser = strtok( bucket, "@");
  143.          hisnode = strtok( NULL, "@");
  144.          if ((*bucket != '@') &&
  145.              equal(hisuser, user ) && (hisnode != NULL) &&
  146.              equal(hisnode, node ) && (strchr( node, '.') == NULL))
  147.          {
  148.             if (equal(hisnode, E_nodename))
  149.                strcpy(node, E_fdomain);
  150.             else {
  151.                strcat(node,".");
  152.                strcat(node,E_localdomain);
  153.             }
  154.  
  155.             ExtractAddress(path, (char *) alias, TRUE);
  156.             if (strlen( path ) == 0)
  157.                sprintf(buffer,"%s@%s", hisuser, node );
  158.             else
  159.                sprintf(buffer,"\"%s\" <%s@%s>", path, hisuser, node);
  160.             fullname = buffer;
  161.          }
  162.          else
  163.             fullname = (char *) alias; /* Use original information      */
  164.       }
  165.    }
  166.    else {
  167.       ExtractAddress(buffer,fullname,TRUE);
  168.       if (strlen(buffer) == 0)      /* A list of users?              */
  169.       {                             /* Yes --> Do recursive call     */
  170.          char *current = buffer;    /* Current token being processed */
  171.          char *next = NULL;         /* Next token to process         */
  172.  
  173.          strcpy(buffer,fullname);
  174.  
  175.          do {
  176.             current = strtok(current,",\t "); /* Get next alias to process */
  177.             next    = strtok(NULL,"");    /* Also save rest of list        */
  178.             header  = ExplodeAlias( header , current, stream, resent);
  179.                                           /* Get alias, including sub-list */
  180.             current  = next;
  181.          } while ( next != NULL );        /* Until no more tokens exist    */
  182.  
  183.          return header;                   /* Have written header, return   */
  184.  
  185.       } /* if */
  186.    } /* else */
  187.  
  188.    if (strpbrk(fullname,"!@") == nil(char))
  189.    {
  190.       sprintf(buffer,"%s@%s", fullname , E_fdomain);
  191.                               /* Local address                    */
  192.       fullname = buffer;      /* Write out the formatted address  */
  193.    }
  194.  
  195.    PutHead(header, fullname, stream, resent);
  196.                               /* Remote address                   */
  197.    return "";                 /* Make header empty string for
  198.                                  next caller                      */
  199. } /* ExplodeAlias */
  200.  
  201. /*--------------------------------------------------------------------*/
  202. /*    A p p e n d _ S i g n a t u r e                                 */
  203. /*                                                                    */
  204. /*    Append the signature file to the specified mailbag file         */
  205. /*                                                                    */
  206. /*    [Broke this code out from Send_Mail to support the ~a mail      */
  207. /*    subcommand]                                                     */
  208. /*                                                                    */
  209. /*    Returns:  0 on success, 1 if signature file not found           */
  210. /*--------------------------------------------------------------------*/
  211.  
  212. static boolean Append_Signature(FILE *mailbag_fp ,